#include <iostream>
using namespace std;
int n;
int idx=0;
const int N=5e5+10;
int tr[N][26];
int e[N];
int get_num(char ch)
{
    return 	ch-'a';
} 
void insert(string&s)
{
	int cur=0;
	for(auto ch:s)
	{
		int path=get_num(ch);
		if(tr[cur][path]==0)tr[cur][path]=++idx;
		cur=tr[cur][path];
		e[cur]++;
	}
}
int find(string& s)
{
	int cur=0;
	for(auto ch:s)
	{
		int path=get_num(ch);
		if(tr[cur][path]==0)return 0;
		cur=tr[cur][path];
	}
	if(e[cur]>0)
	{
		int t=e[cur];
		e[cur]=-1;
		return t;
	}
	return e[cur];
}
int main()
{
	cin>>n;
	while(n--)
	{
		string s;cin>>s;
		insert(s);
	}
	int m;
	cin>>m;
	while(m--)
	{
		string s;cin>>s;
		int ret=find(s);
		if(ret==0)
		{
			cout<<"WRONG"<<endl;
		}
		else if(ret>0)
		{
			cout<<"OK"<<endl;
		}
		else 
		cout<<"REPEAT"<<endl;
	}
	return 0;
}
